package cf.huzpsb.bcgod;

import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Command;

public class HornCMD extends Command {
    public HornCMD(String name, String permission, String... aliases) {
        super(name, permission, aliases);
    }

    public void execute(CommandSender sender, String[] args) {
        if (!(sender instanceof ProxiedPlayer)) {
            sender.sendMessage("§c后台不推荐使用此命令");
        } else if (((ProxiedPlayer) sender).getServer().getInfo().getName().equalsIgnoreCase(Main.login)) {
            sender.sendMessage("§c登录区域禁止使用!");
            return;
        }
        if (args.length != 2) {
            sender.sendMessage("§c参数错误");
        } else {
            int i;
            try {
                i = Integer.parseInt(args[1]);
            } catch (Exception e) {
                sender.sendMessage("§c参数错误");
                return;
            }
            int nh = 0;
            if (Main.horncfg.contains(args[0])) {
                nh = Main.horncfg.getInt(args[0]);
            } else {
                sender.sendMessage("§c警告:本玩家现在没有欢乐券.");
            }
            nh += i;
            if (nh <= 0) {
                nh = 0;
                sender.sendMessage("§c警告:本玩家新的欢乐券数小于或等于0.已经强制设置为0.");
            }
            if (nh == 0) {
                Main.horncfg.set(args[0], null);
            } else {
                Main.horncfg.set(args[0], nh);
            }
            sender.sendMessage("§a玩家" + args[0] + "现在的欢乐券个数为:" + nh);
        }
    }
}
